{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% block title %}{% trans "Products" %}{% endblock %}
{% block inside %}
    <nav id="event-nav" class="header-nav">
        <div class="navigation">
            <div class="navigation-title">
                <h1>{% trans "Products" %}</h1>
            </div>
            {% include "pretixcontrol/event/component_link.html" %}
        </div>
    </nav>
    <p>
        {% blocktrans trimmed %}
            Below, you find a list of all available products. You can click on a product name to inspect and change
            product details. You can also use the buttons on the right to change the order of products within a
            give category.
        {% endblocktrans %}
    </p>
    {% if products|length == 0 %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    You haven't created any products yet.
                {% endblocktrans %}
            </p>

            <a href="{% url "control:event.products.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-primary btn-lg"><i class="fa fa-plus"></i> {% trans "Create a new product" %}</a>
        </div>
    {% else %}
        <p>
            <a href="{% url "control:event.products.add" organizer=request.event.organizer.slug event=request.event.slug %}"
                    class="btn btn-default"><i class="fa fa-plus"></i> {% trans "Create a new product" %}</a>
        </p>
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>{% trans "Product name" %}</th>
                    <th></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th class="iconcol"></th>
                    <th>{% trans "Category" %}</th>
                    <th class="action-col-2"></th>
                    <th class="action-col-2"></th>
                </tr>
                </thead>
                <tbody>
                {% regroup products by category as cat_list %}
                {% for c in cat_list %}
                    {% for i in c.list %}
                        <tr>
                            <td><strong>
                                {% if not i.active %}<strike>{% endif %}
                                <a href="
                        {% url "control:event.product" organizer=request.event.organizer.slug event=request.event.slug product=i.id %}">{{ i }}</a>
                                {% if not i.active %}</strike>{% endif %}
                                </strong>
                                <br>
                                <small class="text-muted">
                                    #{{ i.pk }}
                                    {% for k, c in sales_channels.products %}
                                        {% if k in i.sales_channels %}
                                            <span class="fa fa-fw fa-{{ c.icon }} text-muted"
                                                  data-toggle="tooltip" title="{% trans c.verbose_name %}"></span>
                                        {% else %}
                                        {% endif %}
                                    {% endfor %}
                                </small>
                            </td>
                            <td>
                                {% if i.available_from or i.available_until %}
                                    {% if not i.is_available_by_time %}
                                        <span class="label label-danger" data-toggle="tooltip"
                                                title="{% trans "Currently unavailable since a limited timeframe for this product has been set" %}">
                                            <span class="fa fa-clock-o fa-fw" data-toggle="tooltip">
                                            </span>
                                        </span>
                                    {% else %}
                                        <span class="fa fa-clock-o fa-fw text-muted" data-toggle="tooltip" title="{% trans "Only available in a limited timeframe" %}">
                                        </span>
                                    {% endif %}
                                {% endif %}
                            </td>
                            <td>
                                {% if i.admission %}
                                    <span class="fa fa-user fa-fw text-muted" data-toggle="tooltip" title="{% trans "Admission ticket" %}"></span>
                                {% elif i.issue_giftcard %}
                                    <span class="fa fa-gift fa-fw text-muted" data-toggle="tooltip" title="{% trans "Gift card" %}"></span>
                                {% endif %}
                            </td>
                            <td>
                                {% if i.var_count %}
                                    <span class="fa fa-th-large fa-fw text-muted" data-toggle="tooltip" title="{% trans "Product with variations" %}"></span>
                                {% endif %}
                            </td>
                            <td>
                                {% if i.category.is_addon %}
                                    <span class="fa fa-puzzle-piece fa-fw text-muted" data-toggle="tooltip"
                                            title="{% trans "Only available as an add-on product" %}"></span>
                                {% elif i.require_bundling %}
                                    <span class="fa fa-puzzle-piece fa-fw text-muted" data-toggle="tooltip"
                                          title="{% trans "Only available as part of a bundle" %}"></span>
                                {% elif i.hide_without_voucher %}
                                    <span class="fa fa-tags fa-fw text-muted" data-toggle="tooltip"
                                            title="{% trans "Only visible with a voucher" %}"></span>
                                {% elif i.require_voucher %}
                                    <span class="fa fa-tags fa-fw text-muted" data-toggle="tooltip"
                                            title="{% trans "Can only be bought using a voucher" %}"></span>
                                {% endif %}
                            </td>
                            <td>{% if i.category %}{{ i.category.name }}{% endif %}</td>
                            <td>
                                <a href="{% url "control:event.products.up" organizer=request.event.organizer.slug event=request.event.slug product=i.id %}" class="btn btn-default btn-sm {% if forloop.counter0 == 0 and is_paginated and not page_obj.has_previous %}disabled{% endif %}"><i class="fa fa-arrow-up"></i></a>
                                <a href="{% url "control:event.products.down" organizer=request.event.organizer.slug event=request.event.slug product=i.id %}" class="btn btn-default btn-sm {% if forloop.revcounter0 == 0 and is_paginated and not page_obj.has_next %}disabled{% endif %}"><i class="fa fa-arrow-down"></i></a>
                            </td>
                            <td class="text-right flip">
                                <a href="{% url "control:event.product" organizer=request.event.organizer.slug event=request.event.slug product=i.id %}" class="btn btn-default btn-sm"><i class="fa fa-edit"></i></a>
                                <a href="{% url "control:event.products.add" organizer=request.event.organizer.slug event=request.event.slug %}?copy_from={{ i.id }}" class="btn btn-default btn-sm" title="{% trans "Clone" %}" data-toggle="tooltip"><i class="fa fa-copy"></i></a>
                                <a href="{% url "control:event.products.delete" organizer=request.event.organizer.slug event=request.event.slug product=i.id %}" class="btn btn-delete btn-danger btn-sm"><i class="fa fa-trash"></i></a>
                            </td>
                        </tr>
                    {% endfor %}
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
